import Vue from 'vue'
import VueRouter from 'vue-router'
import BookIndex from '../views/BookIndex.vue'
import BookInfo from '../views/bookInfo/BookInfo.vue'
Vue.use(VueRouter)
// 路由规则
const routes = [
  {
    path: '/BookIndex',
    name: 'BookIndex',
    component: BookIndex,
    children: [
      {
        path: '/bookInfo',
        name: 'BookInfo',
        component: BookInfo // component: () => import('../views/bookInfo/BookInfo.vue')
      },
      {
        path: '/user',
        name: 'User',
        component: () => import('../views/system/UserManager1.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/Login.vue')
  },
  {
    path: '/st',
    name: 'scan',
    component: () => import('../views/scan/index.vue')
  },
  {
    path: '/sc',
    name: 'sc',
    component: () => import('../views/scan/sc.vue')
  },
  {
    path: '/auth',
    name: 'auth',
    component: () => import('../views/student/auth.vue')
  }
  ,
  {
    path: '/stu',
    name: 'stu',
    component: () => import('../views/student/index.vue')
  }
]
// 创建路由对象
const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next()
  } else {
    let token = window.sessionStorage.getItem('token')
    token = localStorage.getItem('token')
    if (token) {
      next()
    } else {
      next()
    }
  }
})
// router.beforeEach((to, from, next) => {
//   debugger
//   if (to.path === '/') {
//     next()
//   } else {
//     const token = window.sessionStorage.getItem('token')
//     if (token) {
//       next()
//     } else {
//       next('/')
//     }
//   }
// })
export default router
